package com.ebase.core.intercepetor;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Package Name:com.ebase.core.intercepetor
 * Description: That's the purpose of the file
 * Date:2016/7/28 11:58
 * Copyright (c) 2016, zhongmu@suneee.com All Rights Reserved.
 */
public class BaseInterceptor extends HandlerInterceptorAdapter {
    protected final Logger logger = Logger.getLogger(BaseInterceptor.class);
    private BaseInterceptor[] nextInterceptor;

    public void setNextInterceptor(BaseInterceptor... nextInterceptor) {
        this.nextInterceptor = nextInterceptor;
    }

    protected boolean nextInterceptor(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        if (nextInterceptor == null) {
            return true;
        }
        for (int i = 0; i < nextInterceptor.length; i++) {
            if (!nextInterceptor[i].preHandle(request, response, handler)) {
                return false;
            }
        }
        return true;
    }
}
